// wtklabel.cpp
//

#include "config.h"
#include "wtk/wtklabel.hpp"

using namespace wtk;



// Label::Label
//
Label::Label ( Widget *parent,
               std::string text )
  : Widget(parent),
    text(text),
    font(new wgl::Font(std::string{WTK_DATADIR} + "/fonts/FreeMono.ttf", 16))
{
}



// Label::on_size_request
//
void Label::on_size_request ( SizeRequest &req )
{
  // [FIXME] add a 1 pixel margin because chars might not appear at
  // all if raster pos is outside of viewport
  font->get_text_size(text, req.width, req.height);
  req.width += 2;
  req.height += 2;
}



// Label::draw
//
void Label::draw ( const DrawContext &context )
{
  font->render_text_image(text, 1.f, 1.f - font->get_scaled_descent());
}
